﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LiveStream
{
    public partial class PlaybackWindowChrome : UserControl
    {
        public PlaybackWindowChrome()
        {
            InitializeComponent();
			WireUpParentWindow();
        }

        private Window _parentWindow = null;
        public Window ParentWindow
        {
            get 
			{
				if (_parentWindow == null)
				{
					_parentWindow = Window.GetWindow(this);
				}

				return _parentWindow;
			}
         }

        private void WireUpParentWindow()
        {
            DragBar.MouseLeftButtonDown += new MouseButtonEventHandler((s, ea) => ParentWindow.DragMove());
        }

        private void DragBar_MouseEnter(object sender, MouseEventArgs e)
        {
            (sender as FrameworkElement).Opacity = 1;
        }

        private void DragBar_MouseLeave(object sender, MouseEventArgs e)
        {
            (sender as FrameworkElement).Opacity = 0;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (ParentWindow.WindowState == WindowState.Maximized)
            {
                ParentWindow.WindowState = WindowState.Normal;
            }
            else
            {
                ParentWindow.WindowState = WindowState.Maximized;

                if (ParentWindow.Width > 1920)//TODO: get rid of this hack
                {
                    ParentWindow.Width = 1920;
                    ParentWindow.Height = 1080;
                }
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ParentWindow.Close();
        }
    }
}
